package com.ruoyi.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.purchase.domain.DictData;
import com.ruoyi.purchase.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * DictDataController
 * 
 * @author kevinness
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/DictData/DictData")
public class DictDataController extends BaseController
{
    @Autowired
    private IDictDataService dictDataService;

    /**
     * 分页查询DictData列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DictData dictData)
    {
        startPage();
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        return getDataTable(list);
    }

    /**
     * 查询所有的DictData列表
     */
    @PostMapping("/getList")
    public AjaxResult getList(@RequestBody DictData dictData){
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        return success(list);
    }

    /**
     * 导出DictData列表
     */
    @Log(title = "DictData", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DictData dictData)
    {
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        ExcelUtil<DictData> util = new ExcelUtil<DictData>(DictData.class);
        util.exportExcel(response, list, "DictData数据");
    }

    /**
     * 获取DictData详细信息
     */
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(dictDataService.selectDictDataByCode(code));
    }

    /**
     * 新增DictData
     */
    @Log(title = "DictData", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DictData dictData)
    {
        return toAjax(dictDataService.insertDictData(dictData));
    }

    /**
     * 修改DictData
     */
    @Log(title = "DictData", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DictData dictData)
    {
        return toAjax(dictDataService.updateDictData(dictData));
    }

    /**
     * 删除DictData
     */
    @Log(title = "DictData", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(dictDataService.deleteDictDataByCodes(codes));
    }
}
